package org.wkg.lesson11;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class Demo_1104 {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(10);
        System.out.println("比赛开始");
        for (int i = 0; i < 10; i++) {
            Thread player = new Thread(() -> {
                try {
                    System.out.println(Thread.currentThread().getName() + "开跑.");
                    TimeUnit.SECONDS.sleep(1);
                    System.out.println(Thread.currentThread().getName() + "到达终点.");

                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                countDownLatch.countDown();
            });
            player.start();
        }

        TimeUnit.MILLISECONDS.sleep(10);
        System.out.println("比赛进行中");
        countDownLatch.await();
        System.out.println("颁奖");
    }
}
